home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_04 / allison / lifetime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-10  |  319 b   |  30 lines

  1. LISTING 3 -
  2. /* lifetime.c:  Illustrate static storage duration */
  3.  
  4. #include <stdio.h>
  5.  
  6. main()
  7. {
  8.     int count(void);
  9.     int i;
  10.  
  11.     for (i = 0; i < 5; ++i)
  12.         printf("%d\n",count());
  13.     return 0;
  14. }
  15.  
  16. int count(void)
  17. {
  18.     static int n = 0;
  19.  
  20.     return ++n;
  21. }
  22.  
  23. /* Output:
  24. 1
  25. 2
  26. 3
  27. 4
  28. 5
  29. */
  30.